home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / optivc32 / mfstd.h < prev    next >
C/C++ Source or Header  |  1999-03-06  |  58KB  |  1,079 lines

  1. /*  MFstd.h
  2.  
  3.   matrix management functions:
  4.   manipulations on matrices of data type "float"
  5.   (single-precision real numbers)
  6.  
  7.   Copyright (c) 1996-1999 by Martin Sander
  8.   All Rights Reserved.
  9. */
  10.  
  11. #if !defined( __MFSTD_H )
  12. #define __MFSTD_H
  13. #if !defined( __MATLIB_H )
  14. #include <MatLib.h>
  15. #endif
  16. #if !defined( __VFSTD_H )
  17. #include <VFstd.h>
  18. #endif
  19. #if !defined( __VFMATH_H )
  20. #include <VFmath.h>
  21. #endif
  22.  
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26.  
  27. /*************   Dynamic Generation of Matrices   ************************/
  28.  
  29. fMatrix __vf  MF_matrix(  unsigned ht, unsigned len );
  30. fMatrix __vf  MF_matrix0( unsigned ht, unsigned len );
  31.     /*  notice that, in the memory model HUGE,
  32.         neither len nor ht may exceed 8191            */
  33.  
  34. /***************************************************************************
  35.  *  The following definitions ensure compatibility between dynamically     *
  36.  *  and statically allocated matrices. The definitions are somewhat        *
  37.  *  cumbersome, but the result for you is that you need not care about     *
  38.  *  the differences between the two types.                                 *
  39.  *  (Internally, the address of the first element of any matrix is needed; *
  40.  *  the expression "MA[0]" is evaluated in a different way for both types, *
  41.  *  but yields in either case the correct address to be passed to the      *
  42.  *  function you wish to call.)                                            *
  43.  *  Only in the rare case that you need to pass the address of one of      *
  44.  *  these functions as an argument to another function, you have to use    *
  45.  *  the actual run-time functions defined further below. Be careful with   *
  46.  *  this: future development of compilers may allow us to avoid this un-   *
  47.  *  handy scheme of macros. So future versions of MatrixLib may no longer  *
  48.  *  use these run-time names.                                              *
  49.  ***************************************************************************/
  50.  
  51.  
  52. /***  Addressing single elements of dynamically allocated matrices: ******
  53.      These two functions are for compatibility with Pascal
  54.      (where elements of dynamically allocated matrices are not directly
  55.      accessible), and for getting around the pointer arithmetics bug in
  56.      some versions of Borland C++.                                         */
  57.  
  58. #define MF_Pelement( MA, ht, len, m, n ) MFPelement( MA[0], ht, len, m, n )
  59.                      /* returns a pointer to MA[m][n]. */
  60. #define MF_element( MA, ht, len, m, n ) (*MFPelement( MA[0], ht, len, m, n ))
  61.                      /* dereferenced pointer */
  62.  
  63.  /****************  Initialization  ***************************************
  64.  
  65.     To initialize all elements of a matrix with the same value,
  66.     or to perform arithmetic operations on all elements simultaneously,
  67.     refer to the functions of VectorLib, declared in <VFstd.h>, <VFmath.h>.
  68.     In order to use the VectorLib functions, utilize the feature that
  69.     the whole matrix occupies one contiguous area in memory: pass the
  70.     address of the first row to the desired vector function, the size
  71.     of the "vector" being ht * len.
  72.     For example, initialize all elements of the matrix MA with 1.0
  73.     (this is *NOT* the identity matrix)  by calling
  74.         VF_equ1( MA[0], ht * len );
  75. */
  76.  
  77. #define MF_equ0( MA, ht, len )            VF_equ0( MA[0], ((ui)ht)*len )
  78. #define MF_equ1( MA, len )                MFequ1( MA[0], len )
  79.                        /* this is the identity matrix */
  80. #define MF_outerprod( MA, X, Y, ht, len ) MFouterprod( MA[0], X, Y, ht, len )
  81.                        /* sizX=ht, sizY=len */
  82. #define MF_Row_equC( MA, ht, len, iRow, C ) \
  83.                                         MFRow_equC( MA[0], ht, len, iRow, C )
  84. #define MF_Col_equC( MA, ht, len, iCol, C ) \
  85.                                         MFCol_equC( MA[0], ht, len, iCol, C )
  86. #define MF_Dia_equC( MA, len, C )       MFDia_equC( MA[0], len, C )
  87.  
  88. #define MF_Row_equV( MA, ht, len, iRow, X ) \
  89.                                         MFRow_equV( MA[0], ht, len, iRow, X )
  90. #define MF_Col_equV( MA, ht, len, iCol, X ) \
  91.                                         MFCol_equV( MA[0], ht, len, iCol, X )
  92. #define MF_Dia_equV( MA, len, X )       MFDia_equV( MA[0], len, X )
  93.  
  94. #define MF_equM( MB, MA, ht, len )  VF_equV( MB[0], MA[0], (ui)(ht)*(len) )
  95.  
  96. #define MF_UequL( MA, len ) MFUequL( MA[0], len )
  97. #define MF_LequU( MA, len ) MFLequU( MA[0], len )
  98.          /* copy lower-diagonal elements into upper-diagonal
  99.            (or vice versa) by index-reflection, so as to
  100.            get a symmetric matrix    */
  101.  
  102.             /* data-type conversions:  */
  103. #define M_DtoF( MF, MD, ht, len ) V_DtoF( MF[0], MD[0], ((ui)ht)*len )
  104. #define M_EtoF( MF, ME, ht, len ) V_EtoF( MF[0], ME[0], ((ui)ht)*len )
  105. #define M_FtoD( MD, MF, ht, len ) V_FtoD( MD[0], MF[0], ((ui)ht)*len )
  106. #define M_FtoE( ME, MF, ht, len ) V_FtoE( ME[0], MF[0], ((ui)ht)*len )
  107.  
  108.             /* suitable windows for MF_spectrum: */
  109. #define MF_Hanning( MA, ht, len )  MFHanning( MA[0], ht, len )
  110. #define MF_Parzen( MA, ht, len )   MFParzen( MA[0], ht, len )
  111. #define MF_Welch( MA, ht, len )    MFWelch( MA[0], ht, len )
  112.  
  113. /********  Extracting a submatrix and copying a submatrix back  *********/
  114.  
  115. #define MF_submatrix( MSub, subHt, subLen, \
  116.                       MSrce, srceHt, srceLen, \
  117.                       firstRowInCol, sampInCol, firstColInRow, sampInRow ) \
  118.                MFsubmatrix(  MSub[0], subHt, subLen, \
  119.                              MSrce[0], srceHt, srceLen, \
  120.                              firstRowInCol, sampInCol, firstColInRow, sampInRow )
  121.  
  122. #define MF_submatrix_equM( MDest, destHt, destLen, \
  123.                            firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  124.                            MSrce, srceHt, srceLen ) \
  125.                MFsubmatrix_equM(  MDest[0], destHt, destLen, \
  126.                              firstRowInCol, sampInCol, firstColInRow, sampInRow, \
  127.                              MSrce[0], srceHt, srceLen )
  128.  
  129. /*****   Extracting a single row or a single column or the diagonal  ******
  130.  *       and storing it into a vector                                     */
  131.  
  132. #define MF_Row_extract( Y, MA, ht, len, iRow ) \
  133.                                      MFRow_extract( Y, MA[0], ht, len, iRow )
  134. #define MF_Col_extract( Y, MA, ht, len, iCol ) \
  135.                                      MFCol_extract( Y, MA[0], ht, len, iCol )
  136. #define MF_Dia_extract( Y, MA, len ) MFDia_extract( Y, MA[0], len )
  137.  
  138.  
  139. /*****************    Basic arithmetic operations *********************
  140.                       performed on one single row,
  141.                       or one single column of any matrix,
  142.                       or on the diagonal of a square matrix
  143.  
  144.     Note: In contrast to the analogous VectorLib functions, the operations
  145.     are performed in-place, i.e. the input matrix itself is changed  */
  146.  
  147. #define MF_Row_addC( MA, ht, len, iRow, C ) \
  148.                                      MFRow_addC( MA[0], ht, len, iRow, C )
  149. #define MF_Col_addC( MA, ht, len, iCol, C ) \
  150.                                      MFCol_addC( MA[0], ht, len, iCol, C )
  151. #define MF_Dia_addC( MA, len, C )    MFDia_addC( MA[0], len, C )
  152.  
  153. #define MF_Row_addV( MA, ht, len, iRow, X ) \
  154.                                      MFRow_addV( MA[0], ht, len, iRow, X )
  155. #define MF_Col_addV( MA, ht, len, iCol, X ) \
  156.                                      MFCol_addV( MA[0], ht, len, iCol, X )
  157. #define MF_Dia_addV( MA, len, X )    MFDia_addV( MA[0], len, X )
  158.  
  159. #define MF_Row_subC( MA, ht, len, iRow, C ) \
  160.                                      MFRow_addC( MA[0], ht, len, iRow, (-C) )
  161. #define MF_Col_subC( MA, ht, len, iCol, C ) \
  162.                                      MFCol_addC( MA[0], ht, len, iCol, (-C) )
  163. #define MF_Dia_subC( MA, len, C )    MFDia_addC( MA[0], len, (-C) )
  164.  
  165. #define MF_Row_subV( MA, ht, len, iRow, X ) \
  166.                                      MFRow_subV( MA[0], ht, len, iRow, X )
  167. #define MF_Col_subV( MA, ht, len, iCol, X ) \
  168.                                      MFCol_subV( MA[0], ht, len, iCol, X )
  169. #define MF_